package com.campus.config;

import com.campus.common.JWTUtil;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class TokenProvider {


    public Long getCurrentUserId(HttpServletRequest request) {
        String token = resolveToken(request);
        System.out.println(token+"-------------------------");
        if (token != null) {
            return JWTUtil.getUserId(token);
        }
        return null;
    }

    // 从请求头中解析出token
    private String resolveToken(HttpServletRequest request) {
        String bearerToken = request.getHeader("token");
        return bearerToken;

    }
}